package com.hs.room.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.hs.room.model.archive.DevReader
import kotlinx.coroutines.flow.Flow

@Dao
interface DevReaderDao {

    @Insert
    suspend fun insert(d: DevReader)

    @Update
    suspend fun update(d: DevReader): Int

    @Query("SELECT * FROM dev_deader where :name = name")
    fun selectByName(name: String): DevReader

    @Query("SELECT * FROM dev_deader")
    fun getAll(): Flow<List<DevReader>>

    @Query("SELECT * FROM dev_deader ORDER BY localId LIMIT :limit OFFSET :offset ")
    fun get(limit: Int, offset: Int): Flow<List<DevReader>>

    @Query("SELECT name FROM dev_deader")
    fun getName(): Flow<List<String>>

    @Query("SELECT boardMac FROM dev_deader")
    fun getIds(): Flow<List<Int>>

    @Query("SELECT count(*) FROM dev_deader")
    fun count(): Int

    @Delete
    suspend fun delete(d: DevReader)
}